﻿using log4net.Appender;
using log4net.Core;

namespace Bridge.Base.Utilities
{
    /// <summary>
    /// Class for appending information to the <see cref="BridgeReporter"/>.
    /// </summary>
    public class BridgeReporterAppender : AppenderSkeleton
    {
        /// <summary>
        /// Appends a logging event to the <see cref="BridgeReporter"/>.
        /// </summary>
        /// <param name="loggingEvent"><see cref="LoggingEvent"/> to report.</param>
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (loggingEvent.ExceptionObject != null)
            {
                BridgeReporter.Report(loggingEvent.LoggerName, loggingEvent.RenderedMessage, loggingEvent.Level, loggingEvent.ExceptionObject);
            }
            else
            {
                BridgeReporter.Report(loggingEvent.LoggerName, loggingEvent.RenderedMessage, loggingEvent.Level);
            }
        }
    }
}
